<?php 
if(isset($_POST['submit'])){ 
    $dbHost = "localhost";         
    $dbUser = "loco";             
    $dbPass = "1q2w3e4r";             
    $dbDatabase = "pizzagamers";     
     
    //Connect to the database
    $db = mysql_connect($dbHost,$dbUser,$dbPass)or die("Error connecting to database."); 
    //Selects the appropriate database
    mysql_select_db($dbDatabase, $db)or die("Couldn't select the database."); 

      
    //Lets search the databse for the user name and password 
    //Choose some sort of password encryption, I choose sha256 
    //Password function (Not In all versions of MySQL). 
    $usr = mysql_real_escape_string($_POST['username']); 
    $pas = mysql_real_escape_string($_POST['password']); 
    $sql = mysql_query("SELECT * FROM user 
        WHERE e_mail='$usr' AND 
        password='$pas' 
        LIMIT 1"); 
    if(mysql_num_rows($sql) == 1){ 
    	$row = mysql_fetch_array($sql); 
        session_start(); 
        $_SESSION['user'] = $row['e_mail']; 
        $_SESSION['logged'] = TRUE;
        if($_POST['username'] == 'admin') {
        	header("Location: ../vue/admin_page.php");
        } else {
        	header("Location: ../vue/confirmation_page.php");
        }  
        exit; 
    } else {
    	session_start();
    	$_SESSION['logged'] = FALSE;
        exit; 
    } 
} else {     
    header("Location: ../vue/index.php");     
    exit; 
} 
?>